<template>
  <transition name="dialog-fade">
    <el-dialog
      v-if="showseachDialog"
      :title="dialogTitle"
      class="dialog-seach"
      :visible.sync="showseachDialog"
      width="800px"
      append-to-body
      @close="closeDialog(0)"
    >
      <el-form ref="formInfo" :model="formInfo" class="demo-form-inline" label-width="100px">
        <el-form-item label="客户手机/客户昵称：" prop="name" label-width="200px">
          <el-input v-model="formInfo.name" placeholder="请输入用户手机/昵称" />
        </el-form-item>
        <el-form-item label="标签：" prop="label" label-width="200px">
          <!-- <el-input v-model.number="formInfo.code" type="number" onkeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))" /> -->
          <el-input v-model="formInfo.label" placeholder="请输入用户标签" />
        </el-form-item>
        <el-form-item style="text-align: right;">
          <el-button @click="closeDialog(0)">取消</el-button>
          <el-button type="primary" @click="submitForm('formInfo')">确定</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </transition>
</template>

<script>
import { getUserList } from "@/api/user";
import Base64 from "@/utils/base";

// import { getuserid } from '../../utils/auth'
export default {
  name: "DialogSeach",
  inject:["reload"],
  props: {
    // msg: {
    //   type: String,
    //   default: ''
    // },
    dialogTitle: {
      type: String,
      default: ""
    },
    itemInfo: {
      type: Object,
      default: function() {
        return {};
      }
    }
  },
  data() {
    return {
      showseachDialog: false,
      formInfo: {
        name: "",
        page: 1,
        label: ""
      },
      // tableData:""
    }
  },
  mounted() {
    // this.getOpt()
  },
  methods: {
    submitForm(formName) {
      const that = this;
      //   const params = Object.assign(that.formInfo, {});
      that.$refs[formName].validate(valid => {
        if (valid) {
          getUserList({
            request_data: Base64.encode(JSON.stringify(this.formInfo))
          }).then(res => {
             if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
            // this.tableData = res.result.data;
            localStorage.setItem('searchData', JSON.stringify(res.result.data))
            this.reload()
          });
          that.closeDialog(1);
        } else {
          return false;
        }
      });
    },
    // 关闭弹框
    closeDialog(flag) {
      this.$refs["formInfo"].resetFields();
      this.showseachDialog = false;
      this.$emit("closeDialog", flag);
    }
  }
};
</script>

<style scoped lang="scss">
.dialog-fade-enter-active {
  -webkit-animation: dialog-fade-in 0.3s;
  animation: dialog-fade-in 0.3s;
}
.dialog-fade-leave-active {
  -webkit-animation: dialog-fade-out 0.3s;
  animation: dialog-fade-out 0.3s;
}
@-webkit-keyframes dialog-fade-in {
  0% {
    -webkit-transform: translate3d(0, -20px, 0);
    transform: translate3d(0, -20px, 0);
    opacity: 0;
  }
  100% {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    opacity: 1;
  }
}
@keyframes dialog-fade-in {
  0% {
    -webkit-transform: translate3d(0, -20px, 0);
    transform: translate3d(0, -20px, 0);
    opacity: 0;
  }
  100% {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    opacity: 1;
  }
}
@-webkit-keyframes dialog-fade-out {
  0% {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    opacity: 1;
  }
  100% {
    -webkit-transform: translate3d(0, -20px, 0);
    transform: translate3d(0, -20px, 0);
    opacity: 0;
  }
}
@keyframes dialog-fade-out {
  0% {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    opacity: 1;
  }
  100% {
    -webkit-transform: translate3d(0, -20px, 0);
    transform: translate3d(0, -20px, 0);
    opacity: 0;
  }
}
</style>
